home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-02-04 | 3.0 KB | 154 lines | [TEXT/CWIE] |
- // NetCache Resolver, 1995 (C) Mizutori Tetsuya
- // - main.c, October 8, 1995
- // This document is pretty printed in 10-point Geneva font.
-
- //#define DEBUG 1
-
- #include "NCR_Basic.h"
- #include "NCR_Resolve.h"
- #include "NCR_AppleEvent.h"
- #include "NCR_Event.h"
- #include "NCR_FIle.h"
- #include "NCR_Qsort.h"
- #include "NCR_Error.h"
-
- #ifdef DEBUG
- #include "NCR_Message.h"
- #endif /* DEBUG */
-
- // definitions
-
- // prototype
- /***** main *****/
- void main ( void );
-
- /***** callback for MenuChoice *****/
- OSErr DoOpen ( WindowPtr window );
-
- /***** callback for AppleEvent *****/
- OSErr DoOpenApplication ( void );
- OSErr DoQuitApplication ( void );
- OSErr DoPrintDocument ( void );
- OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count );
-
- /***** Do Operation *****/
- OSErr DoOperation ( FSSpec *theFSSpec );
-
- /***** main *****/
- void main ( void )
- {
- ToolboxInit();
- SetupAppleEvent();
-
- #ifdef DEBUG
- NewMessage();
- // MessageTest();
- // DoOpen( (WindowPtr) nil );
- #endif /* DEBUG */
-
- EventLoop();
-
- ExitToShell();
- }
-
-
- /***** callback for MenuChoice *****/
- OSErr DoOpen ( WindowPtr window )
- {
- FSSpec theFSSpec;
- short numTypes = 1; //-1 for all types;
- OSType typeList[] = {'DBMC', 'TEXT', 0, 0};
- OSErr err;
-
- if ( ! GetFilename( &theFSSpec, numTypes, typeList ) ) return paramErr;
-
- err = DoOperation( &theFSSpec );
-
- return err;
- }
-
-
- /***** callback for AppleEvent *****/
- OSErr DoOpenApplication ( void )
- {
- OSErr err = noErr;
-
- SetupMenuBar();
-
- // err = DoOpen( (WindowPtr) nil );
-
- return err;
- }
-
- OSErr DoQuitApplication ( void )
- {
- // do nothing, here
-
- return noErr;
- }
-
- OSErr DoPrintDocument ( void )
- {
- // do nothing, here.
-
- return noErr;
- }
-
- OSErr DoOpenDocument ( FSSpec *theFSSpec, long index, long count )
- {
- OSErr err;
-
- err = DoOperation( theFSSpec );
-
- return err;
- }
-
- /***** Do Operation *****/
- OSErr DoOperation ( FSSpec *theFSSpec )
- {
- FSSpec theFSSpec2;
- FInfo theFInfo, theFInfo2;
- Handle theHndl = nil;
- long datasize;
- Str63 cacheLog; // read from 'STR#'
- Str31 strFdType;
- OSType fdType = 'TEXT'; // read from 'STR#'
- OSErr err = noErr;
-
- GetIndString( cacheLog, STRID_CACHE, STRIX_CACHE );
- GetIndString( strFdType, STRID_CACHE, STRIX_CACHETYPE );
- BlockMove( &strFdType[1], &fdType, 4 );
-
- theHndl = NewHandleClear( 0 ); // create a Handle 'theHndl'
- if ( (err=MemError()) != noErr ) { ErrorMessageMEM( err, true ); }
-
- err = GetRecordFromFile( theFSSpec, &theFInfo, theHndl, &datasize );
- if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
-
- theFInfo2 = theFInfo;
- theFInfo2.fdType = fdType;
-
- theFSSpec2 = *theFSSpec;
- BlockMove( cacheLog, theFSSpec2.name, cacheLog[0]+1);
-
- #ifdef COMMENT
- do {
- long fileID;
- FSSpec theFSSpec3;
-
- theFSSpec3 = theFSSpec2;
- GenFilename( theFSSpec2.name, theFSSpec3.name );
- } while ( QueryFile( &theFSSpec2, &fileID ) );
- #endif /* COMMENT */
-
- err = WriteFile( &theFSSpec2, &theFInfo2, theHndl, &datasize );
- if ( err != noErr ) { ErrorMessageFS( err, false ); goto out; }
-
- out:
- if ( theHndl != nil ) DisposeHandle( theHndl ); // dispose the Handle 'theHndl'
-
- return err;
- }
-
- // end of program
-